package com.xiaoq.oauth2.thirdpartclient.service;


import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xiaoq.oauth2.thirdpartclient.entity.Client;
import com.xiaoq.oauth2.thirdpartclient.repository.ClientRepository;
import com.xiaoq.vo.PagingVo;

@Transactional
@Service
public class ClientService {

    @Autowired
    private ClientRepository clientRepository;


    public Client findById(Long id) {
        return clientRepository.get(id);
    }

    public void createClient(Client client) {
        client.setClientKey(UUID.randomUUID().toString());
        client.setClientSecret(UUID.randomUUID().toString());
        clientRepository.saveClient(client);
    }

    public void updateClient(Client client) {
        clientRepository.updateClient(client);
    }

    public void deleteClient(Long clientId) {
        clientRepository.deleteClient(clientId);
    }

    public List<Client> findAll(PagingVo pvo) {
        return clientRepository.findAll(pvo);
    }

    public Client findByClientKey(String clientId) {
        return clientRepository.findByClientKey(clientId);
    }


}
